package com.wms.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtils {
    private static String secretKey = "asdfjnqkewfqw";
    private static Long expire = 4125478L;

    public static String generate(Map<String, Object> claims) {
        String jwt = Jwts.builder().addClaims(claims).signWith(SignatureAlgorithm.HS256, secretKey)
                .setExpiration(new Date(System.currentTimeMillis() + expire))
                .compact();
        return jwt;
    }

    public static Claims parasJwt(String token) {
        return Jwts.parser().setSigningKey(secretKey).parseClaimsJws(token).getBody();
    }

    public static boolean user(String token) {
        try {
            JwtUtils.parasJwt(token);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
}
